#!/usr/bin/env bash


docker run  -e MYSQL_ROOT_PASSWORD=123456 --name mysql-master -v /mysql/data/m-1:/var/lib/mysql -v /mysql/master.conf:/etc/mysql/my.cnf -p 3306:3306 -d mysql:5.7
docker run  -e MYSQL_ROOT_PASSWORD=123456 --name mysql-slave  -v /mysql/data/s-1:/var/lib/mysql -v /mysql/slave.conf:/etc/mysql/my.cnf -p 3307:3306 -d mysql:5.7

docker run  -e MYSQL_ROOT_PASSWORD=123456 --name mysql2-master -v /mysql/data/m-2:/var/lib/mysql -v /mysql/master.conf:/etc/mysql/my.cnf -p 4406:3306 -d mysql:5.7
docker run  -e MYSQL_ROOT_PASSWORD=123456 --name mysql2-slave  -v /mysql/data/s-2:/var/lib/mysql -v /mysql/slave.conf:/etc/mysql/my.cnf -p 4407:3306 -d mysql:5.7

echo "所有容器的name-ip"
docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' $(docker ps -aq)

echo "mysql部分,请在mysql客户端-master执行"
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
GRANT REPLICATION SLAVE ON *.* TO 'backup'@'%' IDENTIFIED BY '123456';
SHOW MASTER STATUS;

echo "mysql部分,请在mysql客户端-slave执行"
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
STOP SLAVE;
CHANGE MASTER TO MASTER_HOST='172.17.0.4',MASTER_PORT=3306,MASTER_USER='backup',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=431;
START SLAVE;
SHOW SLAVE STATUS;